SetupTools:
Bonus features not covered in this talk:
Let's say you're trying to make a package called bugkiller and you want to be able run import bugkiller from other Python programs. Assume your folder structure looks like:
|- README.md
|- killer
| |-- __init__.py
| |-- kill.py
| | -- tests
| | |-- test_kill.py
Wherein 'kill.py' contains two functions: spray() and shoot().
And the root folder is named something like bughandler-project. The first thing you need to do is make a setup.py file in the root directory with the contents indicated below and run python setup.py develop:
In [ ]:
from setuptools import setup
setup(
name='bughandler',
packages=['killer']
)
Now when you run import killer you won't get an error. But what if killer isn't your only package? What if you want to add lover later? Isn't defining all the packages going to be tiresome? That's where find_packages comes in. Try this code in your setup.py file:
In [ ]:
from setuptools import setup, find_packages
setup(
name='bughandler',
packages=find_packages()
)
This should have the same effect. Obviously, if you really want your import statement to do something useful, you're going to need to add some content to kill.py and access it via import killer.kill.
Note: Usually your name and your root package have the same string (for example, in the Nengo repository), but I avoided that case here to reduce confusion.
Let's say bughandler depends the PyPi package six any version after 1.9. How can you make sure that the user has that package installed in the least instrusive way? SetupTools has you covered with the install_requires argument to the setup function:
In [ ]:
from setuptools import setup, find_packages
setup(
name='bughandler',
packages=find_packages(),
install_requires=[
"six>=1.9",
],
)
Now if the user doesn't have the right version of six installed, it should be installed for them via PyPi when they run python setup.py develop.
Sometimes you have a standalone application that you want a user to be able to use from their commandline. Regardless of the OS, SetupTools has got you covered here too with the entry_points argument.
Although entry_points can also be used to extend your application with plugins, this section will only focus on creating shell scripts, like the Nengo GUI, with another argument to setup().
In [ ]:
from setuptools import setup, find_packages
setup(
name='bughandler',
packages=find_packages(),
entry_points={
'console_scripts': [
'spray_bug = killer.kill:spray',
'shoot_bug = killer.kill:shoot',
]
}
)
The final product of all this hard work can be found on Seanny123/bugkiller repository.